package com.boarsoft.config.yaml;

import java.util.ArrayList;
import java.util.List;

public class MyYamlNode {

	private MyYamlNode parent;
	/**
	 * 只有parent为null时候，该值才可能有值
	 */
	private String projectRemark;
	/**
	 * name
	 */
	private String name;
	/**
	 * value
	 */
	private String value;
	/**
	 * 注释
	 */
	private String remark;

	/**
	 * 子节点
	 */
	private List<MyYamlNode> children = new ArrayList<>();

	/**
	 * 数组标示：
	 */
	private Boolean arrayFlag = false;
	/**
	 * 存储的数组中的前一个节点的下标
	 */
	private Integer lastNodeIndex;
	/**
	 * 只有数组标示为true，下面的value才有值
	 */
	private List<MyYamlNode> valueList = new ArrayList<>();

	/**
	 * 将其中的value按照index下标顺序进行重拍
	 */
	public void resortValue() {
		if (!arrayFlag || valueList.isEmpty() || null == lastNodeIndex) {
			return;
		}
		// 升序
		valueList.sort((a, b) -> {
			if (null == a.getLastNodeIndex() || null == b.getLastNodeIndex()) {
				return 0;
			}
			return a.getLastNodeIndex() - b.getLastNodeIndex();
		});
		// 是数组的节点也循环下
		valueList.forEach(MyYamlNode::resortValue);
	}

	public MyYamlNode getParent() {
		return parent;
	}

	public void setParent(MyYamlNode parent) {
		this.parent = parent;
	}

	public String getProjectRemark() {
		return projectRemark;
	}

	public void setProjectRemark(String projectRemark) {
		this.projectRemark = projectRemark;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public List<MyYamlNode> getChildren() {
		return children;
	}

	public void setChildren(List<MyYamlNode> children) {
		this.children = children;
	}

	public Boolean getArrayFlag() {
		return arrayFlag;
	}

	public void setArrayFlag(Boolean arrayFlag) {
		this.arrayFlag = arrayFlag;
	}

	public Integer getLastNodeIndex() {
		return lastNodeIndex;
	}

	public void setLastNodeIndex(Integer lastNodeIndex) {
		this.lastNodeIndex = lastNodeIndex;
	}

	public List<MyYamlNode> getValueList() {
		return valueList;
	}

	public void setValueList(List<MyYamlNode> valueList) {
		this.valueList = valueList;
	}
}